// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var footer = require("../footer/footer_main");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var tools = require("tools");
	var css_dialog = require("css_dialog");
	var databind = require("databind");
	var html_receivables_detail = require("./html_receivables_detail.html");
	var html_loan_detail = require("./html_loan_detail.html");
	var html_expense_detail = require("./html_expense_detail.html");
	var storage = window.sessionStorage;
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var oData = {
		pageIndex: pageIndex,
		pageSize: pageSize,
		totalPageCount: totalPageCount,
		totalRecordCount: totalRecordCount,
		billType: 1
	};
	
	var init = function() {
		footer.init();
		$("#footer").removeClass("none");
		leftMenu.init(5);
		topMenu.init(1);
		router.init();
		$(".table-section").removeClass("none");
		$(".footer").removeClass("none");
		inquireBillReceivablePageList();
		$(".receiptVerify").parent().parent().parent().addClass("leftMenu-open");
		$(".receiptVerify").parent().addClass("leftMenu-active");
		initEvent();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			location.href = "../login/login.html";
		}

		$("#leftMenu9").on("click", ".claimManage", function() {
			router.route("claimManage/claimManage.html");
		});

		$("#leftMenu9").on("click", ".insurance1", function() {
			location.href = "../insuranceManage/insuranceManage.html";
		});

		$("#leftMenu9").on("click", ".insurance2", function() {
			location.href = "../insuranceManage/insuranceManage.html";
		});

		$("#leftMenu9").on("click", ".insurance3", function() {
			location.href = "../insuranceManage/insuranceManage.html";
		});

		$("#leftMenu9").on("click", ".insurance4", function() {
			location.href = "../insuranceManage/insuranceManage.html";
		});
		
		//已完成融资
		$(".endFinanceList").unbind("click").click(function() {
			location.href = "../financing/endFinanceList.html";
		});
		//收货通知查询
		$(".recieveNoticeList").unbind("click").click(function() {
			location.href = "../financing/recieveNoticeList.html";
		});
		//放货查询
		$(".deliveryNoticeList").unbind("click").click(function() {
			location.href = "../financing/deliveryNoticeList.html";
		});
		//放款单查询
		$(".loanNoticeList").unbind("click").click(function() {
			location.href = "../financing/loanNoticeList.html";
		});

		$("#main").on("click", ".table-search-button", function() {
			oData.pageIndex = 1;
			oData.pageSize = 10;
			oData.totalPageCount = 1;
			oData.totalRecordCount = 0; //分页初始化
			oData.startDate = $("#verifyReceiptList .startDate").val();
			oData.endDate = $("#verifyReceiptList .endDate").val();
			oData.writeoffNumber = $("#verifyReceiptList .writeoffNumber").val();
			oData.drawee = $("#verifyReceiptList .drawee").val();
			inquireBillReceivablePageList();
		});

	};
	
	var inquireBillReceivablePageList = function(){
		tools.loadList("inquireBillReceivablePageList.json", $("#verifyReceiptBody"), $("#verifyReceiptTpl"), oData, function() {
			$(".verify").unbind("click").click(function() {
				location.href = "../moneyStatementManage/verifyReceipt.html?type=verify&billReceivableId=" + $(this).parents("tr").attr("billReceivableId");
			});
			
			$(".detail").unbind("click").click(function() {
				location.href = "../moneyStatementManage/verifyReceipt.html?type=detail&billReceivableId=" + $(this).parents("tr").attr("billReceivableId");
			});
		});
	};

	return {
		init: init
	};
});